//
//  Possession.m
//  Homepwner
//
//  Created by Xia Yong on 13-3-15.
//  Copyright (c) 2013年 Xia Yong. All rights reserved.
//

#import "Possession.h"

@implementation Possession

@synthesize possessionName = _possessionName;
@synthesize serialNumber = _serialNumber;
@synthesize valueIndollars = _valueIndollars;
@synthesize dateCreated = _dateCreated;

-(NSString *) description {
    return[[NSString alloc] initWithFormat:@"%@ (%@): Worth $%d, recorded on %@", self.possessionName, self.serialNumber, self.valueIndollars, self.dateCreated];
}

-(id) initWithPossessionName:(NSString *)name valueIndollars:(int)value serialNumber:(NSString *)snumber {
    if(self = [super init]) {
        self.possessionName = name;
        self.valueIndollars = value;
        self.serialNumber = snumber;
        self.dateCreated = [[NSDate alloc] init];
    }
    return self;
}

-(id) init {
    return [self initWithPossessionName:@"Possession" valueIndollars:0 serialNumber:@""];
}

+(id) randomPossession {
    NSArray *randomAdjectiveList = [NSArray arrayWithObjects:@"Fluffy", @"Rusty", @"Shiny", nil];
    NSArray *randomNounList = [NSArray arrayWithObjects:@"Bear", @"Spork", @"Mac", nil];
    int adjectiveIndex = rand() % [randomAdjectiveList count];
    int nounIndex = rand() % [randomNounList count];
    NSString *randomName = [NSString stringWithFormat:@"%@ %@", [randomAdjectiveList objectAtIndex:adjectiveIndex], [randomNounList objectAtIndex:nounIndex]];
    int randomValue = rand() % 100;
    NSString *randomSerialNumber = [NSString stringWithFormat:@"%c%c%c%c%c", '0' + rand() % 10, 'A' + rand() % 26, '0' + rand() % 10, 'A' + rand() % 26, '0' + rand() % 10];
    return [[self alloc] initWithPossessionName:randomName valueIndollars:randomValue serialNumber:randomSerialNumber];
}

@end
